//
//  BehaviorSubjectViewController.swift
//  testRxSwift
//
//  Created by 火星人 on 2017/7/25.
//  Copyright © 2017年 火星人. All rights reserved.
//

import UIKit
import RxSwift

class BehaviorSubjectViewController: BaseViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.addTapWithHandle { (tap) in
            
            let disBag = DisposeBag()
            
            // 广播所有事件给订阅者，对于新的订阅者，广播最近的一个事件或者默认值。
            let subject = BehaviorSubject(value: "这是默认值")
            
            subject.subscribe({ (eve) in
                print("1 \(eve)")
            }).disposed(by: disBag)
            
            subject.onNext("11")
            subject.onNext("12")
            
            
            subject.subscribe({ (eve) in
                print("2 \(eve)")
            }).disposed(by: disBag)
            
            subject.onNext("21")
            subject.onNext("22")
            
        }
    }

}
